﻿using FDStudio.Core.Entities;
using FDStudio.Core.Entities.Query;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq.Expressions;
using System.Text;

namespace FDStudio.Core.Repositories
{
    /*
     CreatedOn: 2018-03-07
     CreatedBy: Jackie Lee(天宇遊龍)
     */
    /// <summary>
    /// 只读仓储上下文
    /// </summary>
    public interface IReadOnlyRepositoryContext : IRepositoryContext
    {
        T Get<T>(long id) where T : class, IEntity;

        T Get<T>(Expression<Func<T, bool>> condition) where T : class, IEntity;

        /// <summary>
        /// 获取条数
        /// </summary>
        /// <param name="condition">条件</param>
        /// <returns></returns>
        int Count<T>(Expression<Func<T, bool>> condition) where T : class, IEntity;

        IEnumerable<T> GetList<T>(Expression<Func<T, bool>> condition, IQueryOrder<T> orderBy = null) where T : class, IEntity;

        /// <summary>
        /// 如需调用PageList返回结果，此项需要处理
        /// 参数依次为：原查询语句，查询页索引（1开始），查询页大小，返回分页的语句
        /// </summary>
        Func<string, long, long, SortBy, string> PagingAction { get; }

        /// <summary>
        /// 进行分页操作
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="condition"></param>
        /// <param name="pagingAction">传入查询字符串，根据所需处理并返回结果查询字符串</param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        PagedList<T> GetList<T>(Expression<Func<T, bool>> condition, long pageIndex, long pageSize, IQueryOrder<T> orderBy = null) where T : class, IEntity;

        void ExecuteDataReader(string sql, Action<IDataReader> read, object parameter = null, CommandType commandType = CommandType.Text);

        T ExecuteScalar<T>(string sql, object parameter = null, CommandType commandType = CommandType.Text);

    }
}
